package Array;

import java.util.MissingFormatArgumentException;

public class ErFenChaZhao1 {
    public static void main(String[] args) {
        int [] arr={10,20,30,40,50,60,70,80,90};
         int a = getIndexByele(arr, 50);
        System.out.println(a);
    }
    public static int getIndexByele(int [] arr,int ele) {
        int low = 0;
        int high = arr.length - 1;
        int middle = (low + high) / 2;
        while (low <= high) {
            if (ele == arr[middle]) {
                return middle;
            }
            else if (ele > arr[middle]) {
                low = middle + 1;
            }
            else if (ele < arr[middle]) {
                high = middle - 1;
            }
            middle = (low + high) / 2;

        }
        return -1;
    }
}
